home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Leonardo the Inventor
/
Leonardo The Inventor (93026)(Broderbund)(Riverdeep)(2004).iso
/
LEOWINMV
/
QUIZGAM.DIR
/
00179_Script_GAME HANDLERS
< prev
next >
Wrap
Text File
|
1996-03-19
|
8KB
|
238 lines
-- -----------------------------------------------------------------------------
-- handler displayPartOfQuestionOfTile shows an item of a question in a tile
on displayPartOfQuestionOfTile part,aQuestion,aSprite
global spriteNrOfFirstTileOffset,QCastName,ACastName
displayCastInSprite (part&aQuestion),aSprite
end
-- -----------------------------------------------------------------------------
-- handler processAnswer gets called after user clicks an answer
on processAnswer aQuestion,clickV,nrOfAnswers
global wrongAnswer,feedbackSprite
set currSprite = the clickOn
set currCastName = the name of cast (the castNum of sprite currSprite)
set currQuestion = getQuestionNumberFromCastName(currCastName)
set anAnswer = getAnswerClicked(clickV,currSprite,nrOfAnswers)
-- 1) CORRECT ANSWER
if anAnswer = getCorrectAnswer(value(currQuestion)) then
-- get the feedbacktext for this question
showFeedBack currQuestion,currSprite
-- 1 becomes 001, 10 becomes 010 etc (to match names of soundfiles)
set newNumber = addZeros(currQuestion)
playSound "Answr" & newNumber & ".AIF"
-- show the next question for this tile
showNextQuestionForTile currSprite
-- check if game is over
if checkGameOver() then
go the frame + 1
-- go to the correct animation after the game
set gameNr = getGameNr()
restartGame "Animation"&gameNr
end if
-- 2) WRONG ANSWER
else
sound stop 1
set the visible of sprite feedbackSprite = FALSE
playSound wrongAnswer
end if
end
-- -----------------------------------------------------------------------------
-- handler restartGame resets all sprits & movies to the specified frame containing
-- an animation
on restartGame nextFrame
global gameNr,spriteNrOfFirstTileOffset,spriteNrOfLastTile
setSpritesVisibility (spriteNrOfFirstTileOffset + 1),spriteNrOfLastTile,TRUE
-- set puppets of Q & A to FALSE to prevent them showing during animation
resetPuppetSprites
go frame nextFrame
set gameNr = GameNr + 1
end
-- -----------------------------------------------------------------------------
-- handler resetPuppetSprites sets all puppetSprites of Q & A to FALSE
on resetPuppetSprites
global spriteNrOfFirstTileOffset,coloredTileOffset
set firstSprite = coloredTileOffset + 1
set lastSprite = spriteNrOfFirstTileOffset + (2 * spriteNrOfFirstTileOffset) + 1
setPuppets firstSprite,lastSprite,FALSE
end
-- -----------------------------------------------------------------------------
-- handler getQuestionNumberFromCastName returns the question number from a castName
-- since casts are named "Q"(xx>,"A"<xx> and "F"<xx> this returns only the nr
on getQuestionNumberFromCastName aCastName
set lastChar = the number of chars in aCastName
return char(2) to (lastChar) of aCastName
end
-- -----------------------------------------------------------------------------
-- handler allQuestionsAnswered returns TRUE if all questions in a sprite are answered
on allQuestionsAnswered aQuestion
global questionIndex,questionNumbers,nrOfQuestionsPerTile
set qanswered = getItemFromLineFromVar(questionIndex,aQuestion,questionNumbers)
return value(qanswered) = (nrOfQuestionsPerTile + 1)
end
-- -----------------------------------------------------------------------------
-- handler showFeedBack displays feedback for question aQuestion
on showFeedBack aQuestion,aSprite
global feedBackSprite
-- get the castMember containing feedBack for this Q
set feedBack = "F" & aQuestion
-- set the feedBackSprite to the position of the answer sprite
set feedBackSpritePosition = getSpritePosition(aSprite)
set the visible of sprite feedBackSprite = FALSE
setSpriteToPosition feedBackSprite,feedBackSpritePosition
-- show the feedBack cast on stage
displayCastInSprite feedBack,feedBackSprite
set the visible of sprite feedBackSprite = TRUE
end
-- -----------------------------------------------------------------------------
-- handler displayCastInSprite displays cast aCastName in sprite aSprite
on displayCastInSprite aCastName,aSprite
set the castNum of sprite aSprite to the number of cast aCastName
updateStage
end
-- -----------------------------------------------------------------------------
-- handler addZeros converts 1 into 001, 10 into 010 etc. Returns a string
on addZeros aNumber
if aNumber < 10 then
set aNumber = "00"&aNumber
else
if (aNumber > 9) AND (aNumber < 100) then
set anumber = "0"&aNumber
end if
end if
return aNumber
end
-- -----------------------------------------------------------------------------
-- handler showNextQuestionForTile updates the index so it points to the next question
on showNextQuestionForTile aSprite
global questionNumbers,nrOfQuestionsPerTile,spriteNrOfFirstTileOffset,questionIndex
-- get the tile number (1 - 9) from the sprite the tile is in (3 - 20)
set currTile = (aSprite - spriteNrOfFirstTileOffset) / 2
-- get the index that indicates the next question & update it so it points to next q
set index = getItemFromLineFromVar(questionIndex,currTile,questionNumbers)
set index = integer(index + 1)
set questionNumbers = setItemOfLineOfVartoValue(questionIndex,currTile,questionNumbers,index)
-- Not all questions are answered
if (index <= nrOfQuestionsPerTile) then
-- hide the old feedBack
setColoredTile currTile,aSprite
displayCastInSprite "Q & A Placeholder (white)"(ASPRITE)
-- arguments: atile, questionsprite, answersprite
set qSprite = aSprite - 1
set aSprite = aSprite
getQuestionForTile currTile,qSprite,aSprite
else -- all questions are answered
-- hide the sprite now containing feedback
setSpriteVisibility aSprite,FALSE
showPicture currTile
end if
end
-- -----------------------------------------------------------------------------
-- handler setColoredTile shows a colored tile to indicate the nr of q's answered
-- so far
on setColoredTile currTile,aSprite
global coloredTileOffset,questionIndex,questionNumbers,spriteNrOfFirstTileOffset
set nrOfQuestionsAnswered = getItemFromLineFromVar(questionIndex,currTile,questionNumbers)
set coloredTileSprite = ((aSprite - spriteNrOfFirstTileOffset) / 2) + coloredTileOffset
displayCastInSprite ("coloredTile"&& currTile && nrOfQuestionsAnswered),coloredTileSprite
end
-- -----------------------------------------------------------------------------
-- handler showPicture shows the background behind a tile
on showPicture aTile
global backgroundTileOffset
setSpriteVisibility (aTile + backgroundTileOffset),TRUE
end
-- -----------------------------------------------------------------------------
-- handler checkGameOver returns TRUE if all tiles are turned into pictures
on checkGameOver
global questionIndex,questionNumbers,nrOfTiles,questionIndex,nrOfQuestionsPerTile
-- check all tiles...
repeat with currentTile = 1 to nrOfTiles
-- if there's one not answered, stop checking & return FALSE
if (NOT( allQuestionsAnswered(currentTile) )) then
set checkGameOver = FALSE
exit repeat
else
set checkGameOver = TRUE
end if
end repeat
return checkGameOver
end
-- -----------------------------------------------------------------------------
-- handler playSound plays AIFF sound file aFile with puppetSound
on playSound aFile
global soundFolder,soundHolder
-- copy the AIFF file into a placeHolder in the cast so we can use puppetSound
set delimiter = getPathDelimiter()
swapSoundFile soundFolder & delimiter & aFile
puppetSound soundHolder
updateStage
waitVoiceQGame 1
end